iT邦幫忙

0

Day27專注於特徵工程

d27
  • 分享至 

  • xImage
  •  

我加入一些新的特徵

# MACD 和 Signal 的變化率
    df['MACD_Diff'] = df['MACD'].diff() 
    df['Signal_Diff'] = df['Signal'].diff()

    # 對數回報率 (使用 np.log 進行平穩化)
    df['MA20_Log_Return'] = np.log(df['MA20'] / df['MA20'].shift(1))
    df['MA50_Log_Return'] = np.log(df['MA50'] / df['MA50'].shift(1))
    
    # 對數 ATR
    df['ATR_Log'] = np.where(df['ATR'] > 0, np.log(df['ATR']), 0)

    # 動態波動率指標 (ATR 相對於其 MA 的比例)
    df['ATR_MA14'] = df['ATR'].rolling(window=14).mean()
    df['ATR_Ratio'] = df['ATR'] / df['ATR_MA14'] 
    
    # 動能標準化 (Z-score Standardization)
    df['Momentum_Zscore'] = (df['Momentum'] - df['Momentum'].mean()) / df['Momentum'].std()

再調了Target的權重

if model_kwargs is None:
        custom_weights = {0: 1.0, 1: 1.2} 
        model_kwargs = {"n_estimators":200, "random_state":42, "class_weight": custom_weights}

並將MACD加入我的決策裡面

 # 獲取 MACD 和 Signal 狀態
        macd = df_test["MACD"].iloc[i - 1]
        signal = df_test["Signal"].iloc[i - 1]
        
         if position is None:
            if proba >= confidence_threshold and rsi > rsi_long_entry and macd > signal:
                position = "long"
                entry_price = price_now
                entry_capital = balance * position_size_ratio
                entry_units = entry_capital / entry_price
                balance -= entry_capital * fee_rate  # 手續費
                if debug:
                    print(f"[BUY] @ {price_now:.2f}, Proba={proba:.2f}")

            elif (1 - proba) >= confidence_threshold and rsi < rsi_short_entry and macd < signal:
                position = "short"
                entry_price = price_now
                entry_capital = balance * position_size_ratio
                entry_units = entry_capital / entry_price
                balance -= entry_capital * fee_rate
                if debug:
                    print(f"[SELL] @ {price_now:.2f}, Proba={proba:.2f}")

https://ithelp.ithome.com.tw/upload/images/20251014/20178967tPxJrEN9hN.pnghttps://ithelp.ithome.com.tw/upload/images/20251014/20178967WrwhnCXHHy.png


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言